package com.czkevin.cif.crafting.ingredient;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class VanillaCraftingIngredient implements CraftingIngredient {

    private final ItemStack ingredient;
    private final int amount;

    public VanillaCraftingIngredient(ItemStack ingredient) {
        if(ingredient == null || ingredient.getType() == Material.AIR) throw new IllegalArgumentException("Invalid ingredient! ");
        this.ingredient = ingredient;
        this.amount = ingredient.getAmount();
    }

    @Override
    public boolean matches(ItemStack target) {
        if(target == null) return false;
        if(target.getType() == Material.AIR) return false;
        if(!ingredient.isSimilar(target)) return false;
        return target.getAmount() >= ingredient.getAmount();
    }

    @Override
    public int getAmount() {
        return amount;
    }
}
